<?php
namespace App\Services;



/**
 * Class USDTApiService
 * @package app\services
 * Date 2023/7/27
 * Time 16:31
 * Author 创青春科技 renziming
 */
class USDTApiService
{
    public static $appid = 'pht0nkey';
    public static $appsecret = 'rhowsrhflxdjtaek';
    public static $notify_url = 'https://bsctest.1yuantuoke.com/api/tp_notify/notify';


    public static function pay_unifinedorder($data){
        $url = 'https://www.usdt-api.vip/api/pay/unifiedorder';

        $param = [
            'appid' => self::$appid,
            'pay_money' => $data['pay_money'],
            'money_type' => $data['money_type'],
            'chain_type' => $data['chain_type'],
            'channel_type' => $data['channel_type'],
            'order_sn' => $data['order_sn'],
            'notify_url' => $data['notify_url'] ?? self::$notify_url,
            /*'callback_url' => $data['callback_url'] ?? '',
            'product_name' => $data['product_name'] ?? '',
            'pay_username' => $data['pay_username'] ?? '',
            'attach' => $data['attach'] ?? '',*/
        ];


        $param['signature'] = self::sign($param);

        $res = self::httpcurls($url,[],$param);
        Logger::usdt("=====>",$res);
        return $res;
    }
    public static function httpcurls($sUrl, $aHeader, $aData)
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_URL, $sUrl);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $aHeader);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $aData);
        $sResult = curl_exec($ch);
        if($sError=curl_error($ch)){
            die($sError);
        }
        curl_close($ch);
        return json_decode($sResult,true);
    }


    public static function sign($data){
        ksort($data);
        $sign = strtoupper(md5(urldecode(http_build_query($data)).'&appsecret='.self::$appsecret));
        return $sign;
    }



}
